let fs=require('fs');
fs.open('../async/test.txt','r',function(err,fd){
    if(err){
        return console.error(err);
    }
    console.log('open');
    let buf=Buffer.alloc(1024);
	fs.ftruncate(fd,6,function(err){
		if(err){
			console.log(err);
		}
		console.log('truncated');
		fs.read(fd,buf,0,buf.length,0,function(err,bytes,buf){
		    if(err){
		        console.log(err);
		    }
		    console.log(bytes+' read');
		    if(bytes > 0){
		        console.log(buf.slice(0,bytes).toString());
		    }
		    fs.close(fd,function(err){
		        if(err){
		            console.lor(err);
		        }
		        console.log('closed');
		    });
		});
	});
});
